#include "stdafx.h"

tstring GetLastErrorDescription(bool showMsgBox)
{
	tostingstream sout;
	TCHAR lpMsgBuf[200];
	DWORD dw = GetLastError(); 
	FormatMessage(
		FORMAT_MESSAGE_FROM_SYSTEM,
		NULL,
		dw,
		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
		lpMsgBuf,
		200, NULL );

	sout<<"failed with error"<< dw<<" "<< lpMsgBuf; 

	if(showMsgBox)
		MessageBox(NULL, sout.str().c_str() , TEXT("Error"), MB_OK); 
	return sout.str();
}